<template>
	<view :class="isShowEmptyData ? 'content-empty' : 'content'">
		<view class="empty-data" v-if="isShowEmptyData">
			<view class="empty-data-content">
				<image class="empty-data-image" src="../../../../static/empty_data.png" mode="widthFix"></image>
				<view class="empty-data-title">暂无数据</view>
			</view>
		</view>
		<view v-else>
			<image :src="buildInfo.thumb" mode="aspectFill" style="max-height: 800rpx;"></image>

			<view class="header header-more">
				<view class="horizontal">
					<view class="line"></view>
					<view class="header-text">基本信息</view>
				</view>
				<image class="share-image" src="../../../../static/share.png" mode="widthFix"></image>
			</view>
			<view class="info-list">
				<view class="info-content">
					<text class="info-content-name">地&emsp;&emsp;区</text>
					<text class="info-content-value">{{ buildInfo.area.name }}</text>
				</view>
				<view class="info-content">
					<text class="info-content-name">楼盘名称</text>
					<text class="info-content-value">{{ buildInfo.name }}</text>
				</view>
				<view class="info-content">
					<text class="info-content-name">户&emsp;&emsp;型</text>
					<text class="info-content-value">{{ buildInfo.model.name }}</text>
				</view>
			</view>
			<view class="header">
				<view class="line"></view>
				<view class="header-text">地理位置</view>
			</view>
			<view class="map-container"><map @click="openMap" :latitude="buildInfo.latitude"
					:longitude="buildInfo.longitude" :markers="covers"></map></view>
			<view class="header">
				<view class="line"></view>
				<view class="header-text">案例展示</view>
			</view>
			<view class="list">
				<view class="item" v-for="index in 4" :key="index" @click="openDetailsSample">
					<view v-if="index % 2 == 1">
						<image src="../../../../static/builder_simple1.png" mode="widthFix"></image>
						<view class="item-icon">30m²</view>
					</view>
					<view v-else>
						<image src="../../../../static/builder_simple2.png" mode="widthFix"></image>
						<view class="item-icon">80m²</view>
					</view>
				</view>
			</view>
			<view class="btn" hover-class="btn-hover" type="default" size="mini" @click="isShowConfirm = true">预约</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buildInfo: {
					area: {},
					model: {}
				},
				covers: [{
					latitude: 0,
					longitude: 0,
					iconPath: '../../../../static/location.png'
				}],
				isShowEmptyData: true
			};
		},
		onLoad(e) {
			uni.request({
				url: 'https://baiyi.kent.work/api/v1/system/getBuildDetail',
				method: 'POST',
				data: {
					id: e.id
				},
				success: res => {
					// console.log(res);
					if (res.data.code == 200) {
						this.isShowEmptyData = false;
						this.buildInfo = res.data.data.buildInfo;
						this.covers[0].latitude = parseFloat(this.buildInfo.latitude);
						this.covers[0].longitude = parseFloat(this.buildInfo.longitude);
					} else {
						this.isShowEmptyData = true;
					}
				},
				fail: e => {
					this.isShowEmptyData = true;
				}
			});
		},
		methods: {
			openMap() {
				uni.navigateTo({
					url: `/pages/index/builder/details/map/map?id=${this.buildInfo.id}`
				});
			},
			openDetailsSample() {
				uni.navigateTo({
					url: '/pages/index/builder/details/sample/sample'
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
	}

	.header-text {
		margin-left: 20rpx;
		font-weight: bold;
		font-size: 28rpx;
		color: #333333;
	}

	.header {
		margin-top: 46rpx;
		margin-left: 40rpx;
		margin-right: 40rpx;
	}

	.share-image {
		width: 40rpx;
	}

	.info-content {
		margin-top: 20rpx;

		.info-content-name {
			font-size: 24rpx;
			margin-left: 40rpx;
		}

		.info-content-value {
			font-size: 24rpx;
			font-weight: bold;
			color: #333333;
			margin-left: 60rpx;
		}
	}

	.list {
		display: grid;
		margin-top: 20rpx;
		padding: 0 40rpx;
		grid-template-columns: 1fr 1fr;
		grid-gap: 22rpx;

		.item {
			border-radius: 12rpx;
			box-shadow: 0rpx 4rpx 4rpx 0rpx rgba(0, 0, 0, 0.1);

			.item-icon {
				text-align: center;
				font-size: 24rpx;
			}

			.item-icon::before {
				content: '— ';
				color: #3d9c36;
			}

			.item-icon::after {
				content: ' —';
				color: #3d9c36;
			}
		}
	}

	.map-container {
		padding: 20rpx 40rpx 0rpx 40rpx;
	}

	map {
		width: 100%;
	}
</style>